 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Function       + getByte
    Author         + Youn Kyung Kang 
    Parameter      + str
    Description    + 바이트를 체크하여 반환한다. (일반용)
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
    function getByte(str) {
        str = new String(str);
        var tmp = 0;
        for(var i = 0; i < str.length; i++) {
            var uniCode = str.charCodeAt(i);
            if(uniCode <= 127)
                tmp++;
            else
                tmp = tmp + 2;
        }
        return tmp;
    } 
    
   /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Function       + isOverByte
    Author         + Youn Kyung Kang 
    Parameter      + obj, maxbyte
    Description    + byte 를 체크하여 maxbyte 보다 큰 경우 true 를 반환한다.
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
    function isOverByte(obj, maxbyte) {
        if(getByte(obj.value) > maxbyte)
            return true;
        return false;
    }
   
  /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Function       + getFormatDate1
    Author         + Youn Kyung Kang 
    Parameter      + obj (예 : 20080101)
    Description    + 유효날짜를 반환한다. (예 : 2008-01-01)
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
    function getFormatDate1(obj) {
        var strDate = new Date();
        var strYear;
        var strMonth;
        var strDay;
        if(obj.value.length == 8) {
            strYear = (obj.value).substr(0, 4) + "-";
            strMonth = (obj.value).substr(4, 2) + "-";
            strDay = (obj.value).substr(6, 2)
            obj.value = strYear + strMonth + strDay;
        }
        else {
            obj.value = strDate.getYear() + "-" + strDate.getMonth() + "-" + strDate.getDay();
        }
    }

    /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Function       + getFormatDate2
    Author         + Youn Kyung Kang 
    Parameter      + obj (예 : 2008-01-01)
    Description    + 유효날짜를 반환한다. (예 : 20080101)
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
    function getFormatDate2(obj) {
        obj.value = getRemoveHyphen(obj.value);
    }
    
    /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Function       + isNullMsg
    Author         + Youn Kyung Kang 
    Parameter      + obj, msg
    Description    + 공백을 체크하여 공백인 경우 메시지를 출력한다.
                     true 를 반환한다.
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
    function isNullMsg(obj, msg) {
        if(getTrim(obj.value) == "") {
            alert(msg + " 입력하십시오.");
            obj.focus();
            return true;
        }
        return false;
    }
    
      /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Function       + isNotSelectedMsg
    Author         + Youn Kyung Kang 
    Parameter      + obj, msg
    Description    + 셀렉트 박스의 첫번째가 선택된 경우 메시지를 출력한다.
                     true 를 반환한다.
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
    function isNotSelectedMsg(obj, msg) {
        if(obj.selectedIndex == 0) {
            alert(msg + " 선택하십시오.");
            obj.focus();
            return true;
        }
        return false;
    }

    /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Function       + isNotChecked
    Author         + Youn Kyung Kang 
    Parameter      + obj
    Description    + 체크 박스나 라디오 버튼이 선택되지 않았을 경우 true 를 반환한다.
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
    function isNotChecked(obj) {
        var tmp = 0;
        if(obj.length > 1) {
            for(var i = 0; i < obj.length; i++) {
                if(obj[i].checked)
                    tmp++;
            }
            if(tmp == 0)
                return true;
        }
        else {
            if(!obj.checked)
                return true;
        }
        return false;
    }
    
    /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Function       + isNotCheckedMsg
    Author         + Youn Kyung Kang 
    Parameter      + obj, msg
    Description    + 체크 박스나 라디오 버튼이 선택되지 않았을 경우 메시지를 출력한다.
                     true 를 반환한다.
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
    function isNotCheckedMsg(obj, msg) {
        var tmp = 0;
        if(obj.length > 1) {
            for(var i = 0; i < obj.length; i++) {
                if(obj[i].checked)
                    tmp++;
            }
            if(tmp == 0) {
                alert(msg + " 선택하십시오.");
                obj[0].focus();
                return true;
            }
        }
        else {
            if(!obj.checked) {
                alert(msg + " 선택하십시오.");
                obj.focus();
                return true;
            }
        }
        return false;
    }
    
    /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Function       + isNotNumeral
    Author         + Youn Kyung Kang 
    Parameter      + obj
    Description    + 숫자인지 체크하여 숫자가 아닌 경우 true 를 반환한다.
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
    function isNotNumeral(obj) {
        for(var i = 0; i < obj.value.length; i++) {
            var uniCode = obj.value.charCodeAt(i);
            if(!(uniCode >= 48 && uniCode <= 57))
                return true;
        }
        return false;
    }
  
  	 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Function       + isNotNumeralMsg
    Author         + Youn Kyung Kang 
    Parameter      + obj, msg
    Description    + 숫자인지 체크하여 숫자가 아닌 경우 메시지를 출력한다.
                     true 를 반환한다
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
    function isNotNumeralMsg(obj, msg) {
        for(var i = 0; i < obj.value.length; i++) {
            var uniCode = obj.value.charCodeAt(i);
            if(!(uniCode >= 48 && uniCode <= 57)) {
                alert(msg + " 숫자만 입력하십시오.");
                obj.focus();
                return true;
            }
        }
        return false;
    }
    
    /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Function       + isNotAlphabetMsg
    Author         + Youn Kyung Kang
    Parameter      + obj, msg
    Description    + 알파벳인지 체크하여 알파멧이 아닌 경우 메시지를 출력한다.
                     true 를 반환한다.
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
    function isNotAlphabetMsg(obj, msg) {
        for(var i = 0; i < obj.value.length; i++) {
            var uniCode = obj.value.charCodeAt(i);
            if(!((uniCode >= 65 && uniCode <= 90) || (uniCode >= 97 && uniCode <= 122))) {
                alert(msg + " 알파벳만 입력하십시오.");
                obj.focus();
                return true;
            }
        }
        return false;
    }

    /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Function       + isNotNumeralOrAlphabet
    Author         + Youn Kyung Kang
    Parameter      + obj
    Description    + 알파벳과 숫자인지 체크하여 알파벳과 숫자가 아닌 경우 true 를 반환한다.
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
    function isNotNumeralOrAlphabet(obj) {
        for(var i = 0; i < obj.value.length; i++) {
            var uniCode = obj.value.charCodeAt(i);
            if(!((uniCode >= 48 && uniCode <= 57) || (uniCode >= 65 && uniCode <= 90) || (uniCode >= 97 && uniCode <= 122)))
                return true;
        }
        return false;
    }

    /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Function       + isNotNumeralOrAlphabetMsg
    Author         + Youn Kyung Kang
    Parameter      + obj, msg
    Description    + 알파벳과 숫자인지 체크하여 알파벳과 숫자가 아닌 경우 메시지를 출력한다.
                     true 를 반환한다.
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
    function isNotNumeralOrAlphabetMsg(obj, msg) {
        for(var i = 0; i < obj.value.length; i++) {
            var uniCode = obj.value.charCodeAt(i);
            if(!((uniCode >= 48 && uniCode <= 57) || (uniCode >= 65 && uniCode <= 90) || (uniCode >= 97 && uniCode <= 122))) {
                alert(msg + " 알파벳과 숫자만 입력하십시오.");
                obj.focus();
                return true;
            }
        }
        return false;
    }
    
     /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Function       + checkNumeralInputLengthMsg
    Author         + Youn Kyung Kang
    Parameter      + obj, msg, maxlen
    Description    + 유효자리수의 숫자인지 체크하여 그렇지 않은 경우 메시지를 출력한다.
                     true 를 반환한다
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
    function checkNumeralInputLengthMsg(obj, msg, maxlen) {
        if(isNotNumeral(obj)) {
            alert(msg + " 숫자로 입력하십시오.");
            obj.focus();
            return true;
        }
        if(obj.value.length != maxlen) {
            alert(msg + " " + maxlen + "자리로 입력하십시오.");
            obj.focus();
            return true;
        }
        return false;
    }

    /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Function       + checkNumeralInputNoMsg
    Author         + Youn Kyung Kang
    Parameter      + obj, msg, maxno
    Description    + 유효 숫자인지 체크하여 그렇지 않은 경우 메시지를 출력한다.
                     true 를 반환한다
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
    function checkNumeralInputNoMsg(obj, msg, maxno) {
        if(isNotNumeral(obj.value)) {
            alert(msg + " 숫자로 입력하십시오.");
            obj.focus();
            return true;
        }
        if(obj.value > maxno) {
            alert(msg + " " + maxno + "이하의 숫자로 입력하십시오.");
            obj.focus();
            return true;
        }
        return false;
    }
    
    /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Function       + changeDayOfMonth
    Author         + Youn Kyung Kang
    Parameter      + objFrm
    Description    + 년, 월에 따른 일을 리턴한다
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
    function getDayOfMonth(objFrm) {
        var arraymonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
        var year = objFrm.common_year.options[objFrm.common_year.selectedIndex].value;
        var month = objFrm.common_month.options[objFrm.common_month.selectedIndex].value; 

        if(((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
            arraymonth[1] = "29";

        return arraymonth[month - 1]; 
    }

    function changeDayOfMonth(objFrm) {
        for(i = objFrm.common_day.length; i >- 1; i--)
            objFrm.common_day.options[i] = null; 

        for(i = 1; i <= getDayOfMonth(objFrm); i++) {
            value = i; 
            text = i; 
            optionDay = new Option(value, text);
            objFrm.common_day.options[objFrm.common_day.length] = optionDay;
        } 
        objFrm.common_day.selectedIndex = 0; 
    }
    
     /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Function       + doWindowOpen
    Author         + Youn Kyung Kang
    Parameter      + windowUrl, windowName, intWidth, intHeight, intTop, intLeft, windowProp
    Description    + Window 를 원하는 위치에 띄운다
                     doWindowOpen("windowOpen.htm", "windowOpen", 800, 600, 0, 0, "toolbar=0,menubar=0,resizable=no,scrollbars=no");
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
    function doWindowOpen(windowUrl, windowName, intWidth, intHeight, intTop, intLeft, windowProp) {
        return window.open(windowUrl, windowName, "width="+intWidth+",height="+intHeight+",top="+intTop+",left="+intLeft+","+windowProp);
    }
    
    /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Function       + emailCheck
    Author         + Youn Kyung Kang
    Parameter      + emailStr
    Description    + Email check
        소스 출처: http://javascript.internet.com/forms/email-address-validation.html               
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
    function emailCheck(emailStr) {
		var checkTLD = 1;
		var knownDomsPat = /^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
		var emailPat = /^(.+)@(.+)$/;
		var specialChars = "\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
		var validChars = "\[^\\s" + specialChars + "\]";
		var quotedUser = "(\"[^\"]*\")";
		var ipDomainPat = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
		var atom = validChars + '+';
		var word = "(" + atom + "|" + quotedUser + ")";
		var userPat = new RegExp("^" + word + "(\\." + word + ")*$");
		var domainPat = new RegExp("^" + atom + "(\\." + atom +")*$");
		var matchArray = emailStr.match(emailPat);
	
		if (matchArray == null) {
			return false;
		}
	
		var user = matchArray[1];
		var domain = matchArray[2];
	
		for (i = 0; i < user.length; i++) {
			if (user.charCodeAt(i) > 127) {
				return false;
			}
		}
	
		for (i = 0; i < domain.length; i++) {
			if (domain.charCodeAt(i) > 127) {
				return false;
			}
		}
	
		if (user.match(userPat) == null) {
			return false;
		}
	
		var IPArray = domain.match(ipDomainPat);
		if (IPArray != null) {
			for (var i = 1; i <= 4; i++) {
				if (IPArray[i] > 255) {
					return false;
				}
			}
	
			return true;
		}
	
		var atomPat = new RegExp("^" + atom + "$");
		var domArr = domain.split(".");
		var len = domArr.length;
		for (i = 0; i < len; i++) {
			if (domArr[i].search(atomPat) == -1) {
				return false;
			}
		}
	
		if (checkTLD && domArr[domArr.length - 1].length != 2 &&
			domArr[domArr.length - 1].search(knownDomsPat) == -1) {
	
			return false;
		}
	
		if (len < 2) {
			return false;
		}
	
		return true;
	}
	
	/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Function       + chkAllSelect
    Author         + Youn Kyung Kang
    Parameter      + form
    Description    + 체크박스에 모두 체크
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
	function chkAllSelect(form){  
	 if(  form.checkFlag.checked == true )  {
	    if( document.all['check'] == '[object]'){
	        for ( var i = 0 ; i < form.check.length ; i++ ){
	            form.check[i].checked = true;}
	         form.check.checked = true;
	        return false;
	    }else{
	        alert("선택하고자 하는 목록이 없습니다.");
	        return false;
	    }
	  }else if( form.checkFlag.checked == false ) {
	  	if( document.all['check'] == '[object]'){
	        for ( var i = 0 ; i < form.check.length ; i++ ){
	            form.check[i].checked = false;}
	         form.check.checked = false;   
	        return false;
	    }else{
	        alert("선택하고자 하는 목록이 없습니다.");
	        return false;
	    }
	  }
	  
	}

	/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Function       + chkAllUnSelect
    Author         + Youn Kyung Kang
    Parameter      + form
    Description    + 체크박스선택 모두 해제
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
	function chkAllUnSelect(form){
	    if( document.all['check'] == '[object]'){
	        for ( var i = 0 ; i < form.check.length ; i++ )
	            form.check[i].checked = false;
	        return false;
	    }else{
	        alert("선택하고자 하는 목록이 없습니다.");
	        return false;
	    }
	}
	
	/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Function       + chkRevSelect
    Author         + Youn Kyung Kang
    Parameter      + form
    Description    + 체크박스 선택반전
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
	function chkRevSelect(form){   
	    var value;
	    if( document.all['check'] == '[object]'){
	        for ( var i = 0 ; i < form.check.length ; i++ ){
	            var select_mode = form.check[i].checked;
	            if ( select_mode == 0 ){
	                value = true;
	                select_mode = 1;
	            }else{
	                value = false;
	                select_mode = 0;
	            }
	            form.check[i].checked = value;
	        }
	        return false;
	    }else{
	        alert("선택하고자 하는 목록이 없습니다.");
	        return false;
	    }
	}
	
	/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Function       + getBetweenDays
    Author         + Youn Kyung Kang
    Parameter      + startYear,startMonth,startDay,endYear,endMonth,endDay
    Description    + 날짜 간격 구하기 
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
	function getBetweenDays(startYear,startMonth,startDay,endYear,endMonth,endDay){
		var chk1 = new Date(startYear,startMonth,startDay);
    	var chk2 = new Date(endYear,endMonth,endDay);
		days = Math.floor((chk2.getTime() - chk1.getTime()) / (60*60*24*1000));
    	
    	return days;
		
	}
	
	/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Function       + fnConvertNull
    Author         + Youn Kyung Kang
    Parameter      + str
    Description    + null을 공백으로 바꾸기 
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
	function fnConvertNull(str){
		if(str == "null" || str =="NULL"){str = "";}
		return str;
	}
   
	/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Function       + getDayInterval,toTimeObject
    Author         + sunghoia
    Parameter      + fromDate, toDate
    Description    + fromDate와 toDate의 날짜 간격 구하기
    example.
       	
       	if((getDayInterval(fromDate,to_dt)>30)||(to_dt-fromDate<0)){
				alert('조회기간은 최대 30일간 가능합니다.');
				return;
		}
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
	function getDayInterval(time1,time2){
		var date1 = toTimeObject(time1);
		var date2 = toTimeObject(time2);
		var day = 1000 * 3600 * 24;
		return parseInt((date2-date1)/day,10);
	}
	function toTimeObject(time){
		var year = time.substr(0,4);
		var month = time.substr(4,2);
		var day = time.substr(6,2);
		return new Date(year,month,day);
	}
	/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Function       + fnScheduleModalDialog
    Author         + Youn Kyung Kang
    Input Parameter      + type,key1,key2,key3,key4
    			     	*  type :  List에서 A, pol/pod로 조회할경우 B(부킹 수정할때)
    			     	*  key1 :  type이 A일경우 year, type이 B일경우 startPlcCd(출발 지역 코드)
    			     	*  key2 :  type이 A일경우 month, type이 B일경우 destPlcCd (도착 지역 코드 )
    			     	*  key3 :  type이 B일경우  startCstCode (출발 국가  코드)
    			     	*  key4 :  type이 B일경우  destCstCode (도착 국가  코드 )
    			     	*  result = fnScheduleModalDialog('A','2008','03');
    			     	*  result = fnScheduleModalDialog('B','PUS','AXT','KR','JP');
	Output Parameter      + result : 구분자 ';'로 연결해서 String으로 리턴 
				     	*  type A : VSL_CD;VOY_NO 
				     	*  type B : 
				     	*          선명 코드(VSL_CD);항차코드(VOY_CD);선박명(화면);선적항,인수지명(화면);양하항,목적지명(화면);
				     	* 		   최초 출항 일자(화면);최초 출항 시간(화면);마지막 입항 일자(화면);마지막 입항 시간(화면);
				     	* 		   선적항 포트 코드(POL_PORT_CD,POR_PLC_CD);양하항 포트 코드(POD_PORT_CD,DLY_PLC_CD);
				     	* 		   출발국가코드(POL_CTR_CD,POR_CTR_CD);도착국가코드(POD_CTR_CD,DLY_CTR_CD);
				     	* 		   서류마감(화면);반입마감(화면);EDI신고 마감(화면);
				     	*          pol터미널코드(POL_TRML_CD,DLY_CY_CD);pod터미널코드(POD_TRML_CD);
				     	* 		   MRN(화면);CALLSIANG(화면)
				     	*        
				     	*          
    Description    + 스케줄 조회 공통 팝업창 
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
    
		
    function fnScheduleModalDialog(type,key1,key2,key3,key4){ 
    	var strURL = "/Project_kmtc/VOSD100/popSearchScheduleResult.do?type="+type+"&key1="+key1+"&key2="+key2+"&key3="+key3+"&key4="+key4; 
     	var strPos = "dialogWidth:900px;dialogHeight:1100px;scroll:yes;resizable:yes";
  		var result = new Array(); 
  		
  		//window.open(strURL,"","width=600,height=400,scrollbars=yes");
		result = window.showModalDialog(strURL,'',strPos);  
		
    	return result;
    }